'use strict';
const { Controller } = require('egg');
const Result = require('../util/result');


class AdminController extends Controller {
  async userlist() {
    const res = await this.ctx.service.user.findAll();
    this.ctx.body = Result.success(res);
  }

  async adminList() {
    const res = await this.ctx.service.admin.list();
    this.ctx.body = res;
  }

  async create() {
    const data = this.ctx.request.body;
    const res = await this.ctx.service.admin.create(data);
    this.ctx.body = res;
  }

  async login() {
    const data = this.ctx.request.body;
    const res = await this.ctx.service.admin.login(data);
    this.ctx.body = res;
  }

  async update() {
    const data = this.ctx.request.body;
    const res = await this.ctx.service.admin.update(data);
    this.ctx.body = res;
  }

  async deleteAdmin() {
    const id = this.ctx.request.body;
    const res = await this.ctx.service.admin.delete(id);
    this.ctx.body = res;
  }
}

module.exports = AdminController;
